package bb.lanxing.devices.config;

import android.text.TextUtils;

import bb.lanxing.App;
import bb.lanxing.R;
import bb.lanxing.calc.notify.HeartRateAlert;
import bb.lanxing.common.config.Constants;
import bb.lanxing.lib.devices.base.DeviceConfiguration;
import bb.lanxing.lib.devices.utils.IHeartRateAlert;
import bb.lanxing.manager.RemoteSharedPreference;
import bb.lanxing.manager.SPConstant;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.util.AppFileUtils;
import bb.lanxing.util.ProcessUtil;

public class AppDeviceConfiguration implements DeviceConfiguration {
	private String processName = ProcessUtil.getProcessName();

	@Override
	public boolean isAntPlusEnabled() {
		return true;
	}

	@Override
	public boolean isBiciDebuggable() {
		return App.getContext().isSuperVersion();
	}

	@Override
	public boolean isBiciAutoConnection() {
		return SharedManager.getInstance().isBiCiAutoConnectWithMP();
	}

	@Override
	public boolean isDfuDebuggable() {
		return SharedManager.getInstance().isFwTestMode();
	}

	@Override
	public boolean isRunningInHostProcess() {
		return !TextUtils.isEmpty(this.processName) && this.processName.endsWith(":bg");
	}

	@Override
	public boolean isHeartAlertEnable() {
		return RemoteSharedPreference.getInstance().getBoolean(SPConstant.KEY_TTS_HEART_WARNING_ENABLE, false);
	}

	@Override
	public IHeartRateAlert getHeartrateAlert() {
		HeartRateAlert heartRateAlert = new HeartRateAlert(App.getContext(), R.raw.beep);
		heartRateAlert.setAlertValue(RemoteSharedPreference.getInstance().getHeartRateWarningValue());
		heartRateAlert.setEnabled(true);
		return heartRateAlert;
	}

	@Override
	public String getRootDir(int i) {
		return switch (i) {
			case 0 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_DEVICES);
			case 1 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_BICI_DIR, Constants.FIT_DIR);
			case 9 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_SPRINT_DIR, Constants.FIT_DIR);
			case 14 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_DISCOVERY_DIR, Constants.FIT_DIR);
			case 17 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_XOSS_G_DIR, Constants.FIT_DIR);
			case 19 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_VORTEX_DIR, Constants.FIT_DIR);
			case 11 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_IGPS_DIR, Constants.FIT_DIR);
			case 12 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_BRYTEN_DIR, Constants.FIT_DIR);
			case 26 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_CYCLEPLUS_M2_DIR, Constants.FIT_DIR);
			case 27 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_CHILEAF_DIR, Constants.FIT_DIR);
			case 28 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_XOSS_NAV_DIR, Constants.FIT_DIR);
			case 29 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_CYCLEPLUS_M1_DIR, Constants.FIT_DIR);
			case 30 ->
					AppFileUtils.buildExternalDirectoryPath(Constants.PERIPHERAL_DIR, Constants.PRODUCT_X2_PRO_DEVICES, Constants.FIT_DIR);
			default -> null;
		};
	}
}
